//
//  DeskStickiesAppDelegate.m
//  DeskStickies
//
//  Created by Florian Bogner on 5/10/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "DeskStickiesAppDelegate.h"

@implementation DeskStickiesAppDelegate

@synthesize window;
@synthesize textView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	[textView setTextColor:[NSColor whiteColor]];
	
	[self loadText];
}

- (void) loadText {
	NSString* path = [NSString stringWithFormat:@"%@/.DeskStickies.rtf",NSHomeDirectory()];
	NSLog(@"Loading from %@",path); 
	
	[textView readRTFDFromFile:path];
	
	[textView scrollRangeToVisible:NSMakeRange(0, 0)];
}

- (void) saveText {
	NSString* path = [NSString stringWithFormat:@"%@/.DeskStickies.rtf",NSHomeDirectory()];
	NSLog(@"Saving to %@",path);
	
	[[textView RTFFromRange:NSMakeRange(0, [[textView textStorage] length])] 
	 writeToFile:path atomically:YES];
}

- (void)applicationWillTerminate:(NSNotification *)notification {
	[self saveText];
}

- (void)applicationWillBecomeActive:(NSNotification *)notification {
	[window setWindowLevel:front];
}

- (void)applicationWillResignActive:(NSNotification *)notification {
	[window setWindowLevel:desktop];

}

@end
